package com.ambow.core.controller;


import com.ambow.core.dqUtil.RoleUtil;
import com.ambow.core.po.DqComment;
import com.ambow.core.po.DqGame;
import com.ambow.core.service.DqCommentService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.dq.gamepropaganda.common.R;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 评论表 前端控制器
 * </p>
 *
 * @author dq
 * @since 2022-09-05
 */
//跨域
@CrossOrigin
@ApiOperation("评价")
@RestController
@RequestMapping("/admin/dqComment")
public class DqCommentController {

    @Autowired
    private DqCommentService dqCommentService;
    //查
    @GetMapping("/list")
    @ApiOperation("查所有评价")
    public R listAll(){
        List<DqComment> list = dqCommentService.list();
        return R.ok().message("ok").data("list",list);
    }

    //根据游戏id查评价
    @GetMapping("/findCommentListByGameId/{gameId}")
    @ApiOperation("根据游戏id查评价")
    public R findCommentListByGameId(@PathVariable Integer gameId){
        QueryWrapper<DqComment> wrapper = new QueryWrapper<>();
        wrapper.eq("game_id",gameId);
        List<DqComment> list = dqCommentService.list(wrapper);
        return R.ok().message("ok").data("list",list);
    }

    //根据游戏id查好评
    //1好评 0差评
    @PostMapping("/findGoodOrBadCommentListByGameId/{gameId}/{gb}")
    @ApiOperation("根据游戏id查好坏评")
    public R findGoodOrBadCommentListByGameId(@PathVariable Integer gameId,@PathVariable Integer gb){
        QueryWrapper<DqComment> wrapper = new QueryWrapper<>();
        wrapper.eq("game_id",gameId).eq("good_bad",gb);
        List<DqComment> list = dqCommentService.list(wrapper);
        return R.ok().message("ok").data("list",list);
    }

    //写评价
    @PostMapping("/addComment")
    @ApiOperation("写评价")
    public R addComment(@RequestBody DqComment comment){
        if (comment == null){
            return R.ok().message("ok").message("你是怎么进来的?????????");
        }else {
            dqCommentService.save(comment);
            return R.ok().message("ok");
        }
    }


    //我的评价
    @GetMapping("myComment")
    @ApiOperation("我的评价")
    public R myComment(){
        Integer roleId = RoleUtil.getRoleId();
        QueryWrapper<DqComment> wrapper = new QueryWrapper<>();
        wrapper.eq("role_id",roleId);
        List<DqComment> list = dqCommentService.list(wrapper);
        return R.ok().data("myComment",list);
    }



}

